package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author:篍
 * @Date: 2025/09/18 19:38
 * @Description:
 */
@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {
    @Autowired
    private WmNewsService wmNewsService;

    @GetMapping("/{id}")
    public ResponseResult getNews(@PathVariable Integer id) {
        WmNews news = wmNewsService.getById(id);
        return ResponseResult.okResult(news);
    }

    /**
     * 分页获取文章列表
     * @param dto 请求参数
     * @return ResponseResult
     */
    @PostMapping("/list")
    public ResponseResult newsPage(@RequestBody WmNewsPageReqDto dto) {
        return wmNewsService.newsPage(dto);
    }

    /**
     * 文章发布
     * @param dto
     * @return
     */
    @PostMapping("/submit")
    public ResponseResult submitNews(@RequestBody WmNewsDto dto) {
        return wmNewsService.submitNews(dto);
    }

    /**
     * 文章查看
     * @param id
     * @return
     */
    @GetMapping("/one/{id}")
    public ResponseResult findOne(@PathVariable Integer id) {
        return wmNewsService.findOne(id);
    }
}
